﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Baosight.ZNH.ZMCommon;
using Telerik.Windows.Controls.GridView;
using Baosight.Platform.Core;
using Baosight.Platform.Core.ServiceModel;
using Baosight.ZNH.ZMCS.UI.Download;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Telerik.Windows.Controls;

namespace Baosight.ZNH.ZMCE.UI
{
    /// <summary>
    /// 随机资料——台账
    /// </summary>
    /// Copyright:Baosight Software LTD.co Copyright (c) 2011
    /// Company:上海宝信软件股份有限公司
    /// Author: 张志芳
    /// Version: 1.0
    /// History:
    ///       2011-07-08  张志芳   [创建]
    ///
    public partial class ZMCEF5 : EFViewCmes
    {
        public ZMCEF5()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 点击下载附件按钮执行的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DownLoad_HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            TempHyperlink = sender as HyperlinkButton;
            TempHyperlink.IsEnabled = false;
            EIRow row = (TempHyperlink.ParentOfType<GridViewRow>().Item as UIBaseEntity).GetEIRow();
            EIInfo info = new EIInfo();
            info.Attributes.Add(EIConstants.ServiceNameKey, "ZMCEC5");
            info.Attributes.Add(EIConstants.MethodNameKey, "queryFiles");
            info.Attributes.Add("fdKeyId", row["fdKeyId"]);

            HttpServiceAgent agent = new HttpServiceAgent();
            agent.CallService(info, OnQueryDownloadFilesCompleted);
        }

        /// <summary>
        /// 下载附件按钮中查询附件的回调函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnQueryDownloadFilesCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            DownloadView view = new DownloadView();
            view.EIDataContext = new Platform.Core.UI.EIDataContext();
            view.EIDataContext.Update(e.EIInfo);

            CmesWindows _win = new CmesWindows();//构造一个弹出窗口
            _win.ResizeMode = ResizeMode.NoResize;//设置不能修改窗口大小
            _win.Header = view.eTitle;//设置Title
            _win.Content = view;
            _win.Closed += delegate { if (TempHyperlink != null) { TempHyperlink.IsEnabled = true; TempHyperlink = null; } };
            _win.ShowDialog();//模态显示弹出窗口
        }
    }
}
